package com.geolab.controller;

import com.geolab.pojo.ResponseResult;
import com.geolab.pojo.clay.PileLoadTestRecords;
import com.geolab.service.ResponseResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "/clay")
public class PileLoadTestRecordsController {

    @Autowired
    private ResponseResultService resultService;

    @RequestMapping(value = "/AllRecords", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<List<PileLoadTestRecords>> selectClayAllRecords() {
        ResponseResult<List<PileLoadTestRecords>> result = resultService.selectClayAllRecords();
        if (!result.isSuccess()){
            System.out.println("查询失败");
        }
        return result;
    }

    /**
     * 以分页的方式返回结果
     * @param pageId 页数
     * @return
     */
    @RequestMapping(value = "/Records", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<List<PileLoadTestRecords>> selectClayRecordsByPage(@RequestParam("pageId") Integer pageId) {
        ResponseResult<List<PileLoadTestRecords>> result;
        if (pageId == null || pageId <= 0){
            result = new ResponseResult<>(false,"输入的pageId有误",null);
        }else {
            result = resultService.selectClayRecordsByPage(pageId);
            if (!result.isSuccess()) {
                System.out.println("查询失败");
            }
        }
        return result;
    }

    @RequestMapping(value = "/RecordByID", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<PileLoadTestRecords> selectClayById(@RequestParam("ID") Integer ID){
        ResponseResult<PileLoadTestRecords> result;
        if (ID == null || ID <= 0){
            result = new ResponseResult<>(false,"输入的数据ID有误",null);
        }else {
            result = resultService.selectClayById(ID);
            if (!result.isSuccess()){
                System.out.println("按ID查询Sand失败");
            }
        }
        return result;
    }

    @RequestMapping(value = "/RecordsLike", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<List<PileLoadTestRecords>> selectClayLike(@RequestParam("keyword") String keyword){
        ResponseResult<List<PileLoadTestRecords>> result = resultService.selectClayLike(keyword);
        if (!result.isSuccess()) {
            System.out.println("查询失败");
        }
        return result;
    }

    @RequestMapping(value = "/RecordsCount", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<Integer> countClayRecords(){
        ResponseResult<Integer> result = resultService.countClayRecords();
        return result;
    }
}
